package com.bcfn.bshop.common.model;

import java.io.Serializable;

/**
 * 
 * @author LiangGuoNing.
 * 
 * 2019年1月14日 下午6:09:40.
 *
 * 修改记录：
 *
 */
public abstract class BaseModel<K> implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2693980309719643177L;

	public abstract K getId();

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((getId() == null) ? super.hashCode() : getId().hashCode());
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object obj) {
		// Check if reference to same object
		if (this == obj) {
			return true;
		}

		// Checks at object level
		if (obj == null) {
			return false;
		}

		final BaseModel<K> other = (BaseModel<K>) obj;

		if (getId() != other.getId()) {
			if (getId() == null) {
				return false;
			}
			if (!getId().equals(other.getId())) {
				return false;
			}
		}
		
		return true;
	}
	
}
